package cn.wanho.controller.paper;

import cn.wanho.listener.DataListener;
import cn.wanho.listener.DataListenerA;
import cn.wanho.listener.DataListenerB;
import cn.wanho.listener.DataListenerD;
import cn.wanho.rvo.ResultVO;
import cn.wanho.service.*;
import cn.wanho.rvo.myeasyexcel.CmsMultileChoiceQuestionData;
import cn.wanho.rvo.myeasyexcel.CmsSummaryData;
import cn.wanho.rvo.myeasyexcel.CmsTextProgrammerData;
import cn.wanho.rvo.myeasyexcel.CmsTrueFalseData;
import com.alibaba.excel.EasyExcel;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping("/paper")
public class PaperController {
    @Resource
    private PaperService paperService;
   /* @Resource
    private CmsChoiceService cmsChoiceService;
    @Resource
    private CmsSummaryService cmsSummaryService;
    @Resource
    private CmsTrueFalseService cmsTrueFalseService;
    @Resource
    private CmsTextProgrammerService cmsTextProgrammerService;

    @PostMapping("/insertQuestionExcel")
    public String insertQuestionExcel(@RequestParam MultipartFile file) {
        try {
            EasyExcel.read(file.getInputStream(), CmsMultileChoiceQuestionData.class, new DataListener(cmsChoiceService)).sheet().doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "Excel成功插入数据库！！✿✿ヽ(°▽°)ノ✿撒花";
    }

    @PostMapping("/insertExcel")
    public String insertExcel(@RequestParam MultipartFile file) throws IOException {
        try {
            EasyExcel.read(file.getInputStream(), CmsMultileChoiceQuestionData.class, new DataListener(cmsChoiceService)).sheet(0).doRead();
            EasyExcel.read(file.getInputStream(), CmsSummaryData.class, new DataListenerA(cmsSummaryService)).sheet(1).doRead();
            EasyExcel.read(file.getInputStream(), CmsTrueFalseData.class, new DataListenerB(cmsTrueFalseService)).sheet(2).doRead();
            EasyExcel.read(file.getInputStream(), CmsTextProgrammerData.class, new DataListenerD(cmsTextProgrammerService)).sheet(3).doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "Excel成功插入数据库！！✿✿ヽ(°▽°)ノ✿撒花";

    }*/

    /**
     * 创建试卷
     * @param file
     * @param examName
     * @param startTime
     * @param keepTime
     * @return
     * @throws ParseException
     */
    @PostMapping("/createPaper")
    public ResultVO createPaper(@RequestParam MultipartFile file,String examName,String startTime,Integer keepTime) throws ParseException {
        return paperService.createPaper(file, examName,startTime,keepTime);
    }

    @PostMapping("/fillQuestion")
    public ResultVO fillQuestion(Integer paperId, @RequestParam List<Integer> choiceList,@RequestParam List<Integer> completionList,@RequestParam List<Integer> judgeList, @RequestParam List<Integer> otherList){
        return paperService.fillQuestion(paperId,choiceList,completionList,judgeList,otherList);
    }

}
